package com.example.web.controller;


import com.example.democommon.tools.Result;
import com.example.demodao.entity.SysUser;
import com.example.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.*;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author rosszhang
 * @since 2023-01-04
 */
@Slf4j
@RestController
@RequestMapping("/userInfo")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/getUserList")
    public Result<?> getUserList() {
        List<SysUser> list = this.sysUserService.list();
        return Result.OK(list);
    }

    @GetMapping("/getTest")
    public Result<?> getTest() throws ExecutionException, InterruptedException {
        ExecutorService exe = Executors.newFixedThreadPool(15);
        Future<List<SysUser>> result = exe.submit((Callable<List<SysUser>>) sysUserService.list());
        return Result.OK(result.get());
    }

    @GetMapping("/getTest2")
    public Result<?> getTest2() throws ExecutionException, InterruptedException {
        ExecutorService exe = Executors.newFixedThreadPool(15);
        Future<Integer> result = exe.submit(new Callable() {
            @Override
            public Object call() throws Exception {
                log.error("线程查询：{}", 1);
                return sysUserService.count();
            }
        });
        return Result.OK(result.get());
    }

}
